# 导包
from flask import Flask

# 导入基础模块

from flask import request,jsonify,redirect,render_template,flash

# 跨域模块
from flask_cors import CORS 

# 导入时间模块
import time

# 建立flask实例

app = Flask(__name__)

# 利用跨域模块进行封装
CORS(app,cors_allowed_origins="*")

# 导入用户模块
from user_view import user
from course_view import course


# 解决中文乱码
app.config['JSON_AS_ASCII'] = False


# 注册蓝图
app.register_blueprint(user)
app.register_blueprint(course)


# 设置消息闪现密钥
app.secret_key = "123123"

# 视图
@app.route('/',methods=['GET','POST','PUT','DELETE'])
async def hello_world():

	flash("123123")


	my_str = "Hello word"

	return render_template("test.html",my_str=my_str)


	return redirect("http://localhost:8080?username=123")

	# 通过url传参
	data = request.args.get("id")

	# 通过form表单
	data = request.form.get("id")

	print(data)


	return {'code':200,'msg':'你好世界'}


# 耗时任务
async def get_data():

	time.sleep(5)


# 性能接口
@app.route('/data/')
async def mydata():

	print("开始执行")
	#time.sleep(5)
	await get_data()
	print("执行结束")

	return {"msg":"执行结束"}


# 调用实例对象

if __name__ == "__main__":

	app.run(debug=True,host="0.0.0.0",port=5000)